package com.example.administrator.myapplication.set;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Switch;

import com.example.administrator.myapplication.HomeActivity;
import com.example.administrator.myapplication.R;
import com.example.administrator.myapplication.set.about.AboutMainFragment;

import java.io.File;

/**
 * Created by Administrator on 2018/1/10.
 */
public class SetMainFragment extends Fragment{
    private LinearLayout layout_about;
    private LinearLayout layout_useradvice;
    private Toolbar toolbar;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view =inflater.inflate(R.layout.fragment_set_main,container,false);
        toolbar= (Toolbar) getActivity().findViewById(R.id.toobar_set);
        toolbar.setNavigationIcon(R.mipmap.custom_back);
        toolbar.setTitle("设置");
        toolbar.setTitleMarginStart(35);
        toolbar.setTitleTextColor(Color.parseColor("#ffffff"));
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().finish();
            }
        });

        init(view);
        layout_about.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AboutMainFragment frag =new AboutMainFragment();
                getFragment(frag);
            }
        });

        layout_useradvice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UserAdviceFragment frag =new UserAdviceFragment();
                getFragment(frag);
            }
        });


        return view;
    }

    public void init(View view){

        layout_about = (LinearLayout) view.findViewById(R.id.layout_about);
        layout_useradvice = (LinearLayout) view.findViewById(R.id.layout_useradvice);
        toolbar= (Toolbar) getActivity().findViewById(R.id.toobar_set);
    }

    public void getFragment(Fragment fragment){
        FragmentManager fm =getActivity().getFragmentManager();
        FragmentTransaction ft =fm.beginTransaction();
        ft.replace(R.id.fragment_setmain,fragment).commit();

    }
}
